﻿using System;
using System.Configuration;
using System.Globalization;
using System.Windows;
using System.Windows.Markup;
using MadMediaManager.Core.Interfaces.DependencyInjectionSupport;
using MadMediaManager.Views.Shell;

namespace MadMediaManager
{
    public static class ApplicationConfiguration
    {
        public static IInfrastructureConfigurer GetInfrastructureConfigurer()
        {
            var name = ConfigurationManager.AppSettings["Infrastructure"].Split(',');
            return (IInfrastructureConfigurer)Activator.CreateInstance(name[1], name[0]).Unwrap();
        }
    }

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private readonly IInfrastructureConfigurer _configurer = ApplicationConfiguration.GetInfrastructureConfigurer();

        public App()
        {
            _configurer.Configure();

            FrameworkElement.LanguageProperty.OverrideMetadata(
              typeof(FrameworkElement),
              new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            MainWindow window = new MainWindow();
            window.Show();
        }
    }
}
